package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.UmsIntegrationConsumeSetting;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.UmsIntegrationConsumeSettingDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface UmsIntegrationConsumeSettingMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, deductionPerAmount, maxPercentPerOrder, useUnit, couponStatus);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(UmsIntegrationConsumeSetting record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(deductionPerAmount).equalTo(record::getDeductionPerAmount)
                  .set(maxPercentPerOrder).equalTo(record::getMaxPercentPerOrder)
                  .set(useUnit).equalTo(record::getUseUnit)
                  .set(couponStatus).equalTo(record::getCouponStatus);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(UmsIntegrationConsumeSetting record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(deductionPerAmount).equalToWhenPresent(record::getDeductionPerAmount)
                  .set(maxPercentPerOrder).equalToWhenPresent(record::getMaxPercentPerOrder)
                  .set(useUnit).equalToWhenPresent(record::getUseUnit)
                  .set(couponStatus).equalToWhenPresent(record::getCouponStatus);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<UmsIntegrationConsumeSetting> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("UmsIntegrationConsumeSettingResult")
    Optional<UmsIntegrationConsumeSetting> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "UmsIntegrationConsumeSettingResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "deduction_per_amount", property = "deductionPerAmount", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_percent_per_order", property = "maxPercentPerOrder", jdbcType = JdbcType.INTEGER),
            @Result(column = "use_unit", property = "useUnit", jdbcType = JdbcType.INTEGER),
            @Result(column = "coupon_status", property = "couponStatus", jdbcType = JdbcType.INTEGER)
    })
    List<UmsIntegrationConsumeSetting> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, umsIntegrationConsumeSetting, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, umsIntegrationConsumeSetting, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(UmsIntegrationConsumeSetting record) {
        return MyBatis3Utils.insert(this::insert, record, umsIntegrationConsumeSetting, c ->
                c.map(deductionPerAmount).toProperty("deductionPerAmount")
                 .map(maxPercentPerOrder).toProperty("maxPercentPerOrder")
                 .map(useUnit).toProperty("useUnit")
                 .map(couponStatus).toProperty("couponStatus")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(UmsIntegrationConsumeSetting record) {
        return MyBatis3Utils.insert(this::insert, record, umsIntegrationConsumeSetting, c ->
                c.map(deductionPerAmount).toPropertyWhenPresent("deductionPerAmount", record::getDeductionPerAmount)
                 .map(maxPercentPerOrder).toPropertyWhenPresent("maxPercentPerOrder", record::getMaxPercentPerOrder)
                 .map(useUnit).toPropertyWhenPresent("useUnit", record::getUseUnit)
                 .map(couponStatus).toPropertyWhenPresent("couponStatus", record::getCouponStatus)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<UmsIntegrationConsumeSetting> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, umsIntegrationConsumeSetting, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<UmsIntegrationConsumeSetting> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, umsIntegrationConsumeSetting, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<UmsIntegrationConsumeSetting> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, umsIntegrationConsumeSetting, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<UmsIntegrationConsumeSetting> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, umsIntegrationConsumeSetting, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(UmsIntegrationConsumeSetting record) {
        return update(c ->
                c.set(deductionPerAmount).equalTo(record::getDeductionPerAmount)
                 .set(maxPercentPerOrder).equalTo(record::getMaxPercentPerOrder)
                 .set(useUnit).equalTo(record::getUseUnit)
                 .set(couponStatus).equalTo(record::getCouponStatus)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(UmsIntegrationConsumeSetting record) {
        return update(c ->
                c.set(deductionPerAmount).equalToWhenPresent(record::getDeductionPerAmount)
                 .set(maxPercentPerOrder).equalToWhenPresent(record::getMaxPercentPerOrder)
                 .set(useUnit).equalToWhenPresent(record::getUseUnit)
                 .set(couponStatus).equalToWhenPresent(record::getCouponStatus)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
